home *** CD-ROM | disk | FTP | other *** search
- on posePuzzleResponse isCorrect
- global TheMediaQueue, theSound
- if isCorrect then
- set response to "Right"
- set soundNo to random(20)
- else
- set response to "Wrong"
- set soundNo to random(14)
- TheMediaQueue(mFlush)
- end if
- if soundNo <= 9 then
- put "0" after response
- end if
- put soundNo after response
- set theSound to DisposeMedia(theSound)
- set theSound to NewPlaySound(BuildSoundName(response, 1))
- TheMediaQueue(mPlay, theSound, 0, 0, 0, 0)
- end
-
- on MPCcharToNum charIn
- global charLookup
- set numLines to the number of lines in charLookup
- set theChar to charToNum(charIn)
- set charOut to theChar
- if (charOut < 127) or (the machineType <> 256) then
- return charOut
- end if
- repeat with i = 1 to numLines
- if theChar = value(item 1 of line i of charLookup) then
- set charOut to value(item 2 of line i of charLookup)
- end if
- end repeat
- return charOut
- end
-
- on checkAnswer correctAnswers, userAnswer
- set failPos to 0
- repeat while correctAnswers <> EMPTY
- set anAnswer to removeExtraSpaces(line 1 of correctAnswers)
- delete line 1 of correctAnswers
- set pos to checkByChar(anAnswer, userAnswer)
- if pos = 0 then
- return 0
- end if
- set failPos to max(failPos, pos)
- end repeat
- return failPos
- end
-
- on checkByChar theAnswer, userResponse
- set longestLen to max(the number of chars in theAnswer, the number of chars in userResponse)
- repeat with i = 1 to longestLen
- if charToNum(char i of theAnswer) <> charToNum(char i of userResponse) then
- return i
- end if
- end repeat
- return 0
- end
-
- on longestAnswer answers, separator
- set maxLength to 0
- repeat while answers <> EMPTY
- set pos to offset(separator, answers)
- if pos > 0 then
- set anAnswer to char 1 to pos - 1 of answers
- delete char 1 to pos of answers
- else
- set anAnswer to answers
- set answers to EMPTY
- end if
- if the number of chars in anAnswer > maxLength then
- set maxLength to the number of chars in anAnswer
- set biggestAnswer to anAnswer
- end if
- end repeat
- return biggestAnswer
- end
-
- on custom_Alert type, StringNum, var
- if type = 1 then
- alert(line StringNum of field "error messages" & var)
- return
- else
- if type = 2 then
- alert(item 1 of line StringNum of field "error messages" && var && item 2 of line StringNum of field "error messages")
- end if
- end if
- end
-
- on pointInRect p, r
- if value(item 1 of p) > value(item 1 of r) then
- if value(item 1 of p) < value(item 3 of r) then
- if value(item 2 of p) > value(item 2 of r) then
- return value(item 2 of p) < value(item 4 of r)
- end if
- end if
- end if
- return 0
- end
-
- on ButtonPressed buttonSprite, pressedName, transitionName
- set isPressed to 1
- set relaxedCast to the castNum of sprite buttonSprite
- if pressedName <> EMPTY then
- set depressedCast to the number of cast pressedName
- else
- set depressedCast to relaxedCast + 1
- end if
- set the castNum of sprite buttonSprite to depressedCast
- updateStage()
- repeat while the mouseDown
- set isPressed to rollOver(buttonSprite)
- if the castNum of sprite buttonSprite = depressedCast <> isPressed then
- if isPressed then
- set the castNum of sprite buttonSprite to depressedCast
- else
- set the castNum of sprite buttonSprite to relaxedCast
- end if
- updateStage()
- end if
- end repeat
- if (transitionName <> EMPTY) and isPressed then
- set the castNum of sprite buttonSprite to the number of cast transitionName
- else
- set the castNum of sprite buttonSprite to relaxedCast
- end if
- updateStage()
- return isPressed
- end
-
- on removeExtraSpaces theString
- set pos to 1
- repeat while pos <= the number of chars in theString
- set isThisSpace to isSpace(char pos of theString)
- set isNextSpace to isSpace(char pos + 1 of theString)
- if isThisSpace and ((pos = 1) or (pos = the number of chars in theString) or isNextSpace) then
- delete char pos of theString
- next repeat
- end if
- if isThisSpace then
- put " " into char pos of theString
- end if
- set pos to pos + 1
- end repeat
- return theString
- end
-
- on isSpace c
- return (c = " ") or (c = TAB) or (c = RETURN)
- end
-
- on caseStringCompare theString1, theString2
- set theResult to 1
- repeat with i = 1 to the number of chars in theString1
- if charToNum(char i of theString1) <> charToNum(char i of theString2) then
- set theResult to 0
- end if
- end repeat
- if the number of chars in theString1 <> the number of chars in theString2 then
- set theResult to 0
- end if
- return theResult
- end
-
- on globalaccent
- global accentraw, accvowel
- put "s,?,1,n,c" into line 1 of accentraw
- put "223,191,161,241,231,209,199" into line 2 of accentraw
- put "225,233,237,243,250" into line 1 of accvowel
- put "224,232,236,242,249" into line 2 of accvowel
- put "226,234,238,244,251" into line 3 of accvowel
- put "228,235,239,246,252" into line 4 of accvowel
- put "a,e,i,o,u" into line 5 of accvowel
- end
-
- on checkaccent
- global accent, keycodeObj, keyToPress, accvowel, accentraw
- if the machineType = 256 then
- if accent and (keyToPress = 0) then
- set curkey to the key
- if accent < 5 then
- repeat with i = 1 to 5
- if item i of line 5 of accvowel = curkey then
- dontPassEvent()
- if the shiftDown = 0 then
- set keyToPress to integer(item i of line accent of accvowel)
- else
- set keyToPress to integer(item i of line accent of accvowel) - 32
- end if
- exit repeat
- end if
- end repeat
- set accent to 0
- else
- if the shiftDown then
- repeat with i = 2 to 5
- if item i of line 1 of accentraw = curkey then
- if i < 4 then
- set keyToPress to integer(item i of line 2 of accentraw)
- else
- set keyToPress to integer(item i + 2 of line 2 of accentraw)
- end if
- dontPassEvent()
- exit repeat
- end if
- end repeat
- else
- repeat with i = 1 to 5
- if item i of line 1 of accentraw = curkey then
- set keyToPress to integer(item i of line 2 of accentraw)
- dontPassEvent()
- exit repeat
- end if
- end repeat
- end if
- set accent to 0
- end if
- else
- set curkey to the key
- if the commandDown then
- if curkey = "z" then
- set accent to 5
- else
- if curkey = "u" then
- set accent to 4
- else
- if curkey = "\" then
- set accent to 2
- else
- if curkey = "i" then
- set accent to 3
- else
- if curkey = "e" then
- set accent to 1
- end if
- end if
- end if
- end if
- end if
- if accent then
- set keyToPress to -1
- dontPassEvent()
- return 0
- end if
- end if
- end if
- end if
- return 0
- end
-
- on min a, b
- if a < b then
- return a
- end if
- return b
- end
-
- on max a, b
- if a > b then
- return a
- end if
- return b
- end
-
- on sign num
- if num < 0 then
- return -1
- end if
- return 1
- end
-
- on clamp value, min, max
- if value > max then
- return max
- end if
- if value < min then
- return min
- end if
- return value
- end
-